import Api from '@/services/api.js'
export default {
  components: {
  },
  data() {
    return {
      tabs: ['国内', '国外'],
      currTab: '国内', //选中的tab  默认国内
      cityData: {// 城市数据
        recentlyCity: {
          nameObj: {}
        }
      },
      cityType: '', // 选择的城市类型
      currCity: {},  //当前选择的城市
    }
  },
  onLoad() {
  },
  onShow() {
  },
  computed: {
    //当前定位信息
    location() {
      return this.$store.state.location;
    }
  },
  async mounted() {
    this.getCityList();
  },
  methods: {
    // 获取城市列表
    async getCityList() {
      const { suc, result } = await this.$request({
        url: Api.openCityList,
        data: {
          lat: this.location.lat_x + '',
          lng: this.location.lng_y + ''
        }
      })
      if (suc) {
        this.cityData = result;
      }
    },
    handleTab(e) {
      const { item } = e.currentTarget.dataset;
      this.currTab = item;
    },
    handleCity(e) {
      const { item, type } = e.currentTarget.dataset;
      this.currCity = {
        ...item,
        id: item.cityid,  // 组装兼容原有取 id 的地方 下同
        name: item.nameObj.name
      };
      this.cityType = type;
    },
    // //确定/重置事件
    handleTap({ type }) {
      if (type == 'confirm') {
        this.$store.commit('setStore', {
          location: {
            city: this.currCity
          }
        })
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.emit('selectCityCallBack', this.currCity);
        uni.navigateBack();
      } else {
        this.currCity = {};
      }
    }
  }
}